<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Up_style extends CI_Controller {

	public function __construct(){
		parent::__construct();

	}

	public function index(){
		$data['ctrlName'] = $this->router->fetch_class();
		$this->load->view('admin/up_style',$data);
	}
/*
| -------------------------------------------------------------------
|  Login Basic Functions
| -------------------------------------------------------------------
*/
	public function authenticate(){
		
		$this->validate->setRule('captcha','string');
		$this->validate->setRule('captcha','message',$this->lang->line('error_captcha'));
		$this->validate->setRule('only_page_css','string');
		$this->validate->setRule('only_page_css','message','only page css 参数没有传');

		if(!$this->validate->run($this->input->post())){
			$this->response->setDetail($this->validate->getMessage());
			$this->response->responseExit();
		}
		$info = $this->validate->getResult();
		
		if(md5(strtolower($info['captcha']).SALT) != $this->session->userdata('captcha')){
			$this->response->setDetail($this->lang->line('error_captcha'));
			$this->response->responseExit();
		}

		

		global $ZM_VERSION;
		$project_code = substr(TEMPLATE_PROJECT, 0,strlen(TEMPLATE_PROJECT)-strlen($ZM_VERSION));// str_replace($ZM_VERSION, '', TEMPLATE_PROJECT);
	
		$url = 'http://html.zmaitech.com/project_force/'.$project_code.'/'.$info['only_page_css'];

		if (!copy($url, dirname(BASEPATH).'/resource/temp.zip')) {
			echo "failed to copy $file...\n";
			die();
		}
		$this->load->library('unzip');
		$a = $this->unzip->extract(dirname(BASEPATH).'/resource/temp.zip');
		foreach ($a as $f) {
			if(strpos($f,'ZM_VERSION.php')>0) {
				copy($f,dirname(BASEPATH).'/resource/ZM_VERSION.php');
			}
		}
		unlink(dirname(BASEPATH).'/resource/temp.zip');
	
		
		$this->response->setSuccess();
		$this->response->setDetail('STYLE UPDATED!!!');
		$this->response->responseExit();
	}


	public function captcha(){
		include APPPATH.'third_party/simple-php-captcha/simple-php-captcha.php';
		
        simple_php_captcha($code,array(
                'width' => 55,
                'height' => 25,
                'angle_max' => 2,
                'min_font_size' => 12,
                'max_font_size' => 12
        ));
        $this->session->set_userdata('captcha',md5(strtolower($code).SALT));
	}
}
/* End of file login.php */
/* Location: ./application/controllers/login.php */